package com.aisile.sellergoods.service.impl;

import com.aisile.entity.PageResult;
import com.aisile.mapper.TbTypeTemplateMapper;
import com.aisile.pojo.TbTypeTemplate;
import com.aisile.pojo.TbTypeTemplateExample;
import com.aisile.sellergoods.service.TypeTemplateService;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;


@Service
public class TypeTemplateServiceImpl implements TypeTemplateService {

    @Autowired
    TbTypeTemplateMapper tbTypeTemplateMapper;
    @Override
    public PageResult findPage(int page, int rows, TbTypeTemplate tbTypeTemplate) {
        PageHelper.startPage(page,rows);
        String name = tbTypeTemplate.getName();
        TbTypeTemplateExample example = new TbTypeTemplateExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }
        Page<TbTypeTemplate> pageModel = (Page<TbTypeTemplate>) tbTypeTemplateMapper.selectByExample(example);
        return new PageResult(pageModel.getTotal(),pageModel.getResult());
    }

    @Override
    public void save(TbTypeTemplate tbTypeTemplate) {
        tbTypeTemplateMapper.insert(tbTypeTemplate);
    }

    @Override
    public TbTypeTemplate findOne(long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }


}
